package restlet.description.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class RESTConfigurationDescription implements RecoverFromSerialization {
	
	List<RESTModuleDescription> moduleDescriptions = new ArrayList<RESTModuleDescription>();
	Map<String,RESTModuleDescription> moduleNames = new HashMap<String,RESTModuleDescription>();
	
	List<String> moduleConfigurationFiles = new ArrayList<String>();
	
	public void compile()
	{
		moduleNames.clear();
		moduleConfigurationFiles.clear();
		for (RESTModuleDescription module : moduleDescriptions) {
			moduleNames.put(module.getName(),module);
			moduleConfigurationFiles.add(module.getPath());
		}
	}
	public void remove(String name) {
		RESTModuleDescription resource = moduleNames.get(name);
		moduleDescriptions.remove(resource);
		moduleNames.remove(name);
	}

	public void replace(String name, RESTModuleDescription newResource) {
		RESTModuleDescription resource = moduleNames.get(name);
		moduleDescriptions.remove(resource);
		moduleDescriptions.add(newResource);
		moduleNames.put(name, newResource);
	}

	public void addModule(RESTModuleDescription newResource) {
		moduleDescriptions.add(newResource);
		moduleNames.put(newResource.getName(), newResource);
	}
	

	public List<String> getModuleConfigurationFiles() {
		return moduleConfigurationFiles;
	}

	public void setModuleConfigurationFiles(List<String> moduleConfigurationFiles) {
		this.moduleConfigurationFiles = moduleConfigurationFiles;
	}
	public List<RESTModuleDescription> getModuleDescriptions() {
		return moduleDescriptions;
	}
	public void setModuleDescriptions(List<RESTModuleDescription> moduleDescriptions) {
		this.moduleDescriptions = moduleDescriptions;
	}
	public Map<String, RESTModuleDescription> getModuleNames() {
		return moduleNames;
	}
	public void setModuleNames(Map<String, RESTModuleDescription> moduleNames) {
		this.moduleNames = moduleNames;
	}
	@Override
	public void recoverFromSerialization() {
		moduleDescriptions = new ArrayList<RESTModuleDescription>();
		moduleNames = new HashMap<String,RESTModuleDescription>();

		
	}

}
